/*
 * @Author: Jimmy
 * @LastModifiedBy: Jimmy
 * @Date: 2024-02-25 09:16:20
 * @LastEditTime: 2024-02-25 15:13:03
 * @FilePath: /react-vite-admin/src/store/permissions/index.ts
 */
import { IRoute } from "@/router/router.types";
import { makeAutoObservable } from "mobx";

class Permissions {
    routes: IRoute[] = [];//用户路由权限
    homeRoute: object = {};//第一个页面地址信息
    buttonPermissions: string[] = [];//用户按钮级权限
    paveRoutes: IRoute[] = [];//打平路由
    sideMenuRoutes: IRoute[] = [];//顶部菜单布局时侧面菜单内容
    breadCrumberList:IRoute[] = [];//路由面包屑

    constructor() {
        //自动观察
        makeAutoObservable(this, {}, { autoBind: true });
    }
    //初始化权限
    init(buttonPermissions: string[],menuRouter: IRoute[],paveRouters: IRoute[],homeRoute: object){
        //更新页面内的操作权限
        this.buttonPermissions = buttonPermissions;
        //更新菜单路由权限
        this.routes = menuRouter
        //更新所有页面权限
        this.paveRoutes = paveRouters
        //更新首页
        this.homeRoute = homeRoute;
    }
    //设置路由权限
    setRoutes(routes:IRoute[]){
        this.routes = routes;
    }
    //设置路由权限中的第一个路由
    setHome(route:IRoute){
        this.homeRoute = route;
    }
    //设置按钮级别的权限
    setButtonPermission(data:string[]){
        this.buttonPermissions = data;
    }
    //扁平化路由设置
    setPaveRoutes(routes:IRoute[]){
        this.paveRoutes = routes;
    }
    //顶部菜单时需要设置侧面菜单
    setSideMenu(routes:IRoute[]){
        this.sideMenuRoutes = routes;
    }
    //设置路由面包屑
    setCrumberList(data:IRoute[]){
        this.breadCrumberList = data;
    }
}

export default Permissions;